package com.pactera.mavenweb.daoimpl;

import java.util.List;

import org.springframework.stereotype.Service;

import com.pactera.mavenweb.dao.BookDao;
import com.pactera.mavenweb.dto.Page;
import com.pactera.mavenweb.entity.Book;

/**
 * BookDao实现类
 * @author SteveXIE
 *
 */
@Service("bookDao")
public class BookDaoImpl extends GenericDaoImpl<Book> implements
	BookDao {
	
	public BookDaoImpl() {
		super(Book.class);
	}

//	@Override
	@SuppressWarnings("unchecked")
	public int saveBook(Book book) {
		try {
			this.insert(book);
			return 0;
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}
	
//	@Override
	@SuppressWarnings("unchecked")
	public Book queryByName(String name) {
		String hql = "from Book where name = ?";
		String[] strArray = {name};
		
		Book book = queryForTopObject(hql, strArray);
		return book;
	}
	
//	@Override
	public int queryAmountForAll() {
		List<Book> bookList = queryAll();
		return bookList.size();
	}
	
	public List<Book> queryAllByPageOrder(Page page) {
		String hql = "from Book order by id ASC";
		return queryForListByPage(hql, null, page);
	}
}